package org.hotpotmaterial.code.controller.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.hotpotmaterial.anywhere.common.mvc.rest.basic.ResultDTO;
import org.hotpotmaterial.code.common.RestStatus;
import org.hotpotmaterial.code.controller.CountDataApi;
import org.hotpotmaterial.code.dto.ResultOfCountDataDTO;
import org.hotpotmaterial.code.dto.ResultOfElDataDTO;
import org.hotpotmaterial.code.service.ICountDataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;

@Controller
public class CountDataController extends BaseController implements CountDataApi {

	@Autowired
	private ICountDataService countDataService;

	@Override
	public ResponseEntity<ResultDTO> people() {
		int perosnCount = countDataService.getPeopleCount();
		long projectCount = countDataService.getProjectCount();
		long apiCount = countDataService.getInterfaceCount();

		return new ResponseEntity<ResultDTO>(
				new ResultOfCountDataDTO().personCount(perosnCount, projectCount, apiCount, 0)
						.message(RestStatus.RESULT_SUCCESS.message()).statusCode(RestStatus.RESULT_SUCCESS.code()),
				HttpStatus.OK);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.hotpotmaterial.code.controller.CountDataApi#line()
	 */
	@Override
	public ResponseEntity<ResultDTO> line() {
		long projectCount = countDataService.getProjectCount();
		long uiCount=countDataService.getUiCount();
		Map<String , Object> ui=new HashMap<String, Object>();
		ui.put("total", projectCount);
		ui.put("ui", uiCount);
		List<Map<String, Object>> lineList = countDataService.getMonthData();
		return new ResponseEntity<ResultDTO>(new ResultOfElDataDTO().personCount(ui, lineList)
				.message(RestStatus.RESULT_SUCCESS.message()).statusCode(RestStatus.RESULT_SUCCESS.code()),
				HttpStatus.OK);
	}

	/* (non-Javadoc)
	 * @see org.hotpotmaterial.code.controller.CountDataApi#active()
	 */
	@Override
	public ResponseEntity<ResultDTO> active(@PathVariable(value = "date", required = true)String date) {
		List<Map<String, Object>> lineList = countDataService.getActiveTop5Data(date);
		return new ResponseEntity<ResultDTO>(new ResultOfElDataDTO().personCount(null, lineList)
				.message(RestStatus.RESULT_SUCCESS.message()).statusCode(RestStatus.RESULT_SUCCESS.code()),
				HttpStatus.OK);
	}

}
